<html>
<head>
	<title>HHP4 LV99点数辅助计算器</title>
	<meta http-equiv='Content-Type' content="text/html; charset=utf-8">
<style>
table{
  background:#e1ebf5;
  border:2px;
  font-size:12px;
}

</style>
</head>
<body bgcolor=#e1ebf5>
<center><strong><font size=+2>HHP4 LV99点数辅助计算器</font></strong></center><p>
<hr>
<table><tr><td><strong>注：在属性表中，黑数象征正常点，<font color=blue>蓝数表示破上限才能加的点数</font>，<font color=red>红数表示错误的点数</font>。如果有红字，HP/SP输出表则失去意义。</strong></td></tr>
<tr><td><div align=center><strong>配点会失态，三思后再交</strong></div></td></tr></table>
<?php require('sql_class_point.php');?>
<?php require('config.php');?>
<form action="" method="post" name="comm_form" id="comm_form" onSubmit="return FrontPage_Form2_Validator(this)">
<table align=left border=1>
<tr><td>
  <div align=center><select name="pid" id="pid" onChange="changelocation_dc(document.comm_form.pid.options[document.comm_form.pid.selectedIndex].value);">
    <option selected value="">请选择牌组</option>
    <?php 
	$rs=$db->execute("select distinct pid,cgroup from cmember order by pid asc");
	while($rows=$db->fetch_array($rs))
	{
echo "<option value=".$rows["pid"].">".$rows["cgroup"]."</option>";
}
$db->free_result($rs);
?>
  </select>
  <script language="javascript">
subcat = new Array();
  <?php
  $rs=$db->execute("select * from cmember where available=1");
  $m=0;
  $k=0;
  
  while($rows=$db->fetch_array($rs)){
  $name1="'".$rows["pid"]."'";
  $name2="'".$rows["cmember"]."'";
  $name3="'".$rows["cid"]."'";
  ?>
subcat[<?php echo $m;?>] = new Array(<?php echo $name2;?>,<?php echo $name1;?>,<?php echo $name3;?>);
<?php
$m++;
$k++;//计算选项元素的个数
}
$db->free_result($rs);
 ?>
var twocount;
twocount=0;
twocount=<?php echo $k;?>;
function changelocation_dc(locationid_dc)
{
document.comm_form.cid.length = 0; 
var locationid_dc=locationid_dc;
var i;
for (i=0;i < twocount; i++)
{
if (subcat[i][1] == locationid_dc)
{ 
  document.comm_form.cid.options[document.comm_form.cid.length] = new Option(subcat[i][0], subcat[i][2]); 
  } 
}
}
</script>
  <select name="cid" id="cid">
    <option selected value="">请选择牌名</option>
  </select></div></td></tr>
  <script language=JavaScript>
function FrontPage_Form2_Validator(theForm)
{
  if (theForm.cid.value == "")
  {
    alert("请指定一张人物牌");
    theForm.cid.focus();
    return (false);
  }
  return (true);
}

function fillform(obj,str,mgr,spd,vit,luk) {
	obj.pstr.value=str;
	obj.pmgr.value=mgr;
	obj.pspd.value=spd;
	obj.pvit.value=vit;
	obj.pluk.value=luk;
	obj.pstr.focus();
}

</script>
<tr><td>最终力量：<input type=text name=pstr maxlength=2 size=2 value=<?echo $_POST[pstr]?>>
最终魔力：<input type=text name=pmgr maxlength=2 size=2 value=<?echo $_POST[pmgr]?>>
最终速度：<input type=text name=pspd maxlength=2 size=2 value=<?echo $_POST[pspd]?>>
最终耐力：<input type=text name=pvit maxlength=2 size=2 value=<?echo $_POST[pvit]?>>
最终幸运：<input type=text name=pluk maxlength=2 size=2 value=<?echo $_POST[pluk]?>></td></tr>
<tr><td>
  <div align=left>
  <input type=submit name=autop value="自动配点(物攻强化)">
  <input type=submit name=autom value="自动配点(魔攻强化)">
  <input type=submit name=autod value="自动配点(双刀)">
  <input type=checkbox name=rebirth value=1><font color=green>我要重新做人(阴阳石)</font>
</div>
</td></tr>
<tr><td>
  <input type=hidden name=mark>
  <div align=left>
  <input type=submit name=autotp value="自动配点(物龟强化)">
  <input type=submit name=autotm value="自动配点(魔龟强化)">
  <input type=submit name=manup value="检查手动输入配点">
</div>
</td></tr>
</form>
</table>

<?

if(!isset($_POST[mark]))
{
	exit;
}

$rebirth = $_POST['rebirth'];
$cid=$_POST['cid'];
$rs=$db->execute("select * from cmember where cid=$cid");
$rows=$db->fetch_array($rs);
$name=$rows["cmember"];
$groupid=$rows["pid"];
$bblv = $blv=$rows["baselv"];
$bhp=$rows["basehp"];
$bsp=$rows["basesp"];
$bbstr = $bstr=$rows["basestr"];
$bbmgr = $bmgr=$rows["basemgr"];
$bbspd = $bspd=$rows["basespd"];
$bbvit = $bvit=$rows["basevit"];
$bbluk = $bluk=$rows["baseluk"];
$strlimit=($bstr+99-$blv+5)>99 ? 99 : ($bstr+99-$blv+5);
$mgrlimit=($bmgr+99-$blv+5)>99 ? 99 : ($bmgr+99-$blv+5);
$spdlimit=($bspd+99-$blv+5)>99 ? 99 : ($bspd+99-$blv+5);
$vitlimit=($bvit+99-$blv+5)>99 ? 99 : ($bvit+99-$blv+5);
$luklimit=($bluk+99-$blv+5)>99 ? 99 : ($bluk+99-$blv+5);
$pluslv=99-$blv;
$sspoint=$pluslv*3 + floor($pluslv/3);

if($rebirth == 1) {
	$blv=1;
	$bstr = $bmgr = $bspd = $bvit = $bluk = 0;
	$sspoint = 330;
}

if(isset($_POST[manup]))
{
	$pstr=$_POST[pstr];
	$pmgr=$_POST[pmgr];
	$pspd=$_POST[pspd];
	$pvit=$_POST[pvit];
	$pluk=$_POST[pluk];
}elseif(isset($_POST[autop]))
{
	$pstr=$bstr;$pmgr=$bmgr;$pspd=$bspd;$pvit=$bvit;$pluk=$bluk;
	$nowpoint=$sspoint-basepp($pstr,$pmgr,$pspd,$pvit,$pluk);
	if($strlimit<70){
		$nowpoint=$nowpoint-($strlimit-$pstr)-20;
		$pstr=$strlimit+20;
	} else
	{
		$nowpoint=$nowpoint-($strlimit-$pstr);
		$pstr=$strlimit;
	}

	if($nowpoint>=($spdlimit-$pspd))
	{
		$nowpoint=$nowpoint-($spdlimit-$pspd);
		$pspd=$spdlimit;
	} else
	{
		$pspd=$pspd+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>=($vitlimit-$pvit))
	{
		$nowpoint=$nowpoint-($vitlimit-$pvit);
		$pvit=$vitlimit;
	} else
	{
		$pvit=$pvit+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>0)
	{
		$pmgr=$pmgr+$nowpoint;
	}
} elseif(isset($_POST[autom]))
{
	$pstr=$bstr;$pmgr=$bmgr;$pspd=$bspd;$pvit=$bvit;$pluk=$bluk;
	$nowpoint=$sspoint-basepp($pstr,$pmgr,$pspd,$pvit,$pluk);
	if($mgrlimit<70){
		$nowpoint=$nowpoint-($mgrlimit-$pmgr)-20;
		$pmgr=$mgrlimit+20;
	} else
	{
		$nowpoint=$nowpoint-($mgrlimit-$pmgr);
		$pmgr=$mgrlimit;
	}

	if($nowpoint>=($spdlimit-$pspd))
	{
		$nowpoint=$nowpoint-($spdlimit-$pspd);
		$pspd=$spdlimit;
	} else
	{
		$pspd=$pspd+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>=($vitlimit-$pvit))
	{
		$nowpoint=$nowpoint-($vitlimit-$pvit);
		$pvit=$vitlimit;
	} else
	{
		$pvit=$pvit+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>0)
	{
		$pstr=$pstr+$nowpoint;
	}
} elseif(isset($_POST[autod])){
	$pstr=$bstr;$pmgr=$bmgr;$pspd=$bspd;$pvit=$bvit;$pluk=$bluk;
	$nowpoint=$sspoint-basepp($pstr,$pmgr,$pspd,$pvit,$pluk);

	$nowpoint=$nowpoint-($strlimit-$pstr);
	$pstr=$strlimit;
	$nowpoint=$nowpoint-($mgrlimit-$pmgr);
	$pmgr=$mgrlimit;

	if($nowpoint>=($spdlimit-$pspd))
	{
		$nowpoint=$nowpoint-($spdlimit-$pspd);
		$pspd=$spdlimit;
	} else
	{
		$pspd=$pspd+$nowpoint;
		$nowpoint=0;
	}
		
	if($nowpoint>0)
	{
		$pvit=$pvit+$nowpoint;
	}
} elseif(isset($_POST[autotp])){
	$pstr=$bstr;$pmgr=$bmgr;$pspd=$bspd;$pvit=$bvit;$pluk=$bluk;
	$nowpoint=$sspoint-basepp($pstr,$pmgr,$pspd,$pvit,$pluk);

	if($vitlimit<70){
		$nowpoint=$nowpoint-($vitlimit-$pvit)-20;
		$pvit=$vitlimit+20;
	} elseif($vitlimit<80){
		$nowpoint=$nowpoint-(90-$pvit);
		$pvit=90;
	} else{
		$nowpoint=$nowpoint-($vitlimit-$pvit);
		$pvit=$vitlimit;
	}

	if($nowpoint>=($strlimit-$pstr))
	{
		$nowpoint=$nowpoint-($strlimit-$pstr);
		$pstr=$strlimit;
	} else
	{
		$pstr=$pstr+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>=($mgrlimit-$pmgr))
	{
		$nowpoint=$nowpoint-($mgrlimit-$pmgr);
		$pmgr=$mgrlimit;
	} else
	{
		$pmgr=$pmgr+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>0)
	{
		$pspd=$pspd+$nowpoint;
	}
} elseif(isset($_POST[autotm])){
	$pstr=$bstr;$pmgr=$bmgr;$pspd=$bspd;$pvit=$bvit;$pluk=$bluk;
	$nowpoint=$sspoint-basepp($pstr,$pmgr,$pspd,$pvit,$pluk);

	if($vitlimit<70){
		$nowpoint=$nowpoint-($vitlimit-$pvit)-20;
		$pvit=$vitlimit+20;
	} elseif($vitlimit<80){
		$nowpoint=$nowpoint-(90-$pvit);
		$pvit=90;
	} else{
		$nowpoint=$nowpoint-($vitlimit-$pvit);
		$pvit=$vitlimit;
	}

	if($nowpoint>=($mgrlimit-$pmgr))
	{
		$nowpoint=$nowpoint-($mgrlimit-$pmgr);
		$pmgr=$mgrlimit;
	} else
	{
		$pmgr=$pmgr+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>=($strlimit-$pstr))
	{
		$nowpoint=$nowpoint-($strlimit-$pstr);
		$pstr=$strlimit;
	} else
	{
		$pstr=$pstr+$nowpoint;
		$nowpoint=0;
	}

	if($nowpoint>0)
	{
		$pspd=$pspd+$nowpoint;
	}
}

$addstr=$pstr-$bstr;
$addmgr=$pmgr-$bmgr;
$addspd=$pspd-$bspd;
$addvit=$pvit-$bvit;

if($rebirth == 1) {
	switch($groupid) {
		case 0:{$bhp = 40;$bsp = 40;break;}
		case 1:{$bhp = 15;$bsp = 65;break;}
		case 2:{$bhp = 25;$bsp = 55;break;}
		case 3:{$bhp = 45;$bsp = 35;break;}
		case 4:{$bhp = 55;$bsp = 25;break;}
		case 5:{$bhp = 30;$bsp = 50;break;}
		case 6:{$bhp = 20;$bsp = 60;break;}
		case 7:{$bhp = 65;$bsp = 15;break;}
		case 8:{$bhp = 55;$bsp = 25;break;}
		case 9:{$bhp = 35;$bsp = 45;break;}
		case 10:{$bhp = 40;$bsp = 40;break;}
		case 11:{$bhp = 60;$bsp = 20;break;}
		case 12:{$bhp = 70;$bsp = 10;break;}
		case 13:{$bhp = 20;$bsp = 60;break;}
		case 14:{$bhp = 40;$bsp = 40;break;}
		case 15:{$bhp = 30;$bsp = 50;break;}
		case 16:{$bhp = 55;$bsp = 25;break;}
		case 17:{$bhp = 40;$bsp = 40;break;}
		case 18:{$bhp = 35;$bsp = 45;break;}
		case 19:{$bhp = 45;$bsp = 34;break;}
		case 20:{$bhp = 40;$bsp = 40;break;}
		case 21:{$bhp = 45;$bsp = 35;break;}
		default:{$bhp = 40;$bsp = 40;break;}
	}
	$hpoint=$bhp+98*7+$pvit*4+$pspd*2;
	$spoint=$bsp+98*2+$pmgr*2+$pstr*2;
} else {
//	echo "$bhp+$pluslv*8+$addvit*4+$addspd*2+$blv";
	$hpoint=$bhp+$pluslv*8+$addvit*4+$addspd*2+$bblv;
	$spoint=$bsp+$pluslv*3+$addmgr*2+$addstr*2+floor($bblv/2);
}

function basepp(&$str,&$mgr,&$spd,&$vit,&$luk)
{
	$minusp=0;
	if($str<20)
	{
		$minusp=$minusp+(20-$str);
		$str=20;
	}
	if($mgr<20)
	{
		$minusp=$minusp+(20-$mgr);
		$mgr=20;
	}
	if($spd<20)
	{
		$minusp=$minusp+(20-$spd);
		$spd=20;
	}
	if($vit<20)
	{
		$minusp=$minusp+(20-$vit);
		$vit=20;
	}
	if($luk<21)
	{
		$minusp=$minusp+(21-$luk);
		$luk=21;
	}
	return $minusp;
}

function sxcolor($bvalue,$fvalue,$baselv) 
{
	$tcolor="black";
	if($fvalue<20)
	{
		return $tcolor="red";
	}
	$limit=($bvalue+99-$baselv+5)>99 ? 99 : ($bvalue+99-$baselv+5);
	if($fvalue>$limit)
	{
		if(($fvalue-$limit)<=25 && $fvalue<91)
		{
			return $tcolor="blue";
		}
		return $tcolor="red";
	}
	return $tcolor;
}

function errorp($bvalue,$fvalue){
	global $rebirth;
	if ($fvalue<$bvalue && $rebirth != 1)
	{
		return $text="<font color=red>&nbsp;点数少于初始值！</font>";
	}
	return;
}

echo "<table border=1>";
echo "<tr><td><div align=center><strong>$name</strong></div></td></tr>";
echo "<tr><td><div align=center>HP/SP点数</div></td></tr>";
echo "<tr><td>HP：".$bhp."+".($hpoint-$bhp)."=$hpoint</td>";
echo "<tr><td>SP：".$bsp."+".($spoint-$bsp)."=$spoint</td>";
echo "<tr><td><div align=center>最终属性点</div></td></tr>";
echo "<tr><td>力量：".$bstr."+".($pstr-$bstr)."=<font color=".sxcolor($bbstr,$pstr,$bblv).">$pstr".errorp($bbstr,$pstr)."</td>";
echo "<tr><td>魔力：".$bmgr."+".($pmgr-$bmgr)."=<font color=".sxcolor($bbmgr,$pmgr,$bblv).">$pmgr".errorp($bbmgr,$pmgr)."</td>";
echo "<tr><td>速度：".$bspd."+".($pspd-$bspd)."=<font color=".sxcolor($bbspd,$pspd,$bblv).">$pspd".errorp($bbspd,$pspd)."</td>";
echo "<tr><td>耐力：".$bvit."+".($pvit-$bvit)."=<font color=".sxcolor($bbvit,$pvit,$bblv).">$pvit".errorp($bbvit,$pvit)."</td>";
echo "<tr><td>幸运：".$bluk."+".($pluk-$bluk)."=<font color=".sxcolor($bbluk,$pluk,$bblv).">$pluk".errorp($bbluk,$pluk)."</td><tr><td>";
if($rebirth == 1) {
	echo "<tr><td>可分配属性点数：330</td></tr>";
} else {
	echo "<tr><td>可分配属性点数：".$sspoint."</td></tr>";
}

if($rebirth == 1) {
	$allpoint = 330;
	if($_POST['manup']) {
		$sspoint = $_POST[pstr] + $_POST[pmgr] + $_POST[pspd] + $_POST[pvit] + $_POST[pluk];
	}
} else {
	$allpoint=($pstr-$bstr)+($pmgr-$bmgr)+($pspd-$bspd)+($pvit-$bvit)+($pluk-$bluk);
}
if ($allpoint==$sspoint)
{
	echo "<tr><td>已分配属性点数：".$allpoint."，分配完毕。</td></tr>";
} else{
	echo "<tr><td><font color=red>已分配属性点数：".$allpoint."，差".abs($sspoint-$allpoint)."点</font></td></tr>";
}
$db->free_result($rs);
$rs=$db->execute("select skills from cmember where cid=${cid}");
$skills=current($db->fetch_array($rs));
$db->free_result($rs);
if($skills) {
	$rs=$db->execute("select sgid,sname from skill where suid IN ($skills)");
	echo "<tr><td>";
	while($r=$db->fetch_array($rs)) {
		if($r['sgid'] == 14) {
			echo "!!!".$r['sname']."<br>";
		} else {
			echo $r['sname']."<br>";
		}
	}
}
echo "</tr></td>";
echo "<tr><td><div align=center><input type=button value=填充到表单 onclick=fillform(this.form,".$pstr.",".$pmgr.",".$pspd.",".$pvit.",".$pluk.")></div></td></tr>";
mysql_close();
?>
</table>
<p>
</body>
</html>
